/**
 *
 * @author Sergey S Lega
 */

/**
 * @successsor of all abstract active elements, such as PC, switch, firewall and
 * router. Note that Firewall may not to allow access to any network connections
 */

package network.ActiveElements;
import java.util.Collection;
import java.util.Iterator;
import network.Base.IPAddress;
import network.Base.PathElement;

public class ActiveElement implements PathElement{
    public Collection<IPAddress> getIP() {
        if (ip == null) {
            throw new NullPointerException("ip stack is null");
        }
        return ip;
    };

    @Override
    public boolean equals(Object b) {
        if (b.getClass() != this.getClass())
            return false;

        if (b == this)
            return true;

        if (this.hashCode() == b.hashCode())
            return true;

        return false;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 53 * hash + this.id;
        return hash;
    }

    public void AddIP(IPAddress addr) {
        if (addr == null) {
            throw new NullPointerException("addr is null");
        }
        ip.add(addr);
        return;
    }

    public void AddConnection(PathElement connector) {
        if (connector == null) {
            throw new NullPointerException("connector is null");
        }
        connections.add(connector);
        return;
    }

    public ActiveElement (Collection<PathElement> connections_,
            double delay_, double cost_, int id_, Collection<IPAddress> ip_) {

        id = id_;
        delay = delay_;
        cost = cost_;
        id = id_;
        connections = connections_;

        if (ip_ == null) {
            throw new NullPointerException("ip stack is null");
        }

        Iterator<IPAddress> ips_iter = ip_.iterator();
        while (ips_iter.hasNext()) {
            ip.add(ips_iter.next());
        }
    }

    public int getID() {
        return id;
    }

    public String getInfo() {
        return info;
    }

    public Collection<PathElement> getConnections() {
        return connections;
    }

    public double getTimeDelay() {
        return delay;
    }

    public double getCost () {
        return cost;
    }

    private Collection<IPAddress> ip;

    protected double delay;
    protected double cost;
    protected int id;
    protected String info;
    protected Collection<PathElement> connections;

}
